package com.ljx.itbbs.server.mall.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljx.itbbs.server.mall.domain.entity.CouponEntity;
import com.ljx.itbbs.server.mall.mapper.CouponMapper;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
public class CouponDao extends ServiceImpl<CouponMapper, CouponEntity> {

    public List<CouponEntity> getUserCouponListByUId(Long userId){
        return this.baseMapper.getUserCouponListByUId(userId);
    }

    public void reduceStock(Long couponId) {
        lambdaUpdate().setSql("stock = stock - 1")
                .eq(CouponEntity::getId, couponId)
                .gt(CouponEntity::getStock, 0)
                .update();
    }

    public CouponEntity getUserCoupon(Long userId, Long couponId) {
        return this.baseMapper.getUserCoupon(userId, couponId);
    }
}
